package com.esri.core.tasks.ags.geoprocessing;

import com.esri.core.internal.util.d;
import com.esri.core.io.EsriServiceException;
import java.util.ArrayList;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public class GPJobResource {
    private GPJobParameter[] inputParameters;
    private String jobID;
    private JobStatus jobStatus;
    private GPMessage[] messages;
    private GPJobParameter[] outputParameters;

    /* loaded from: classes.dex */
    public enum JobStatus {
        CANCELLED("esriJobCancelled"),
        CANCELLING("esriJobCancelling"),
        DELETED("esriJobDeleted"),
        DELETING("esriJobDeleting"),
        EXECUTING("esriJobExecuting"),
        FAILED("esriJobFailed"),
        NEW_JOB("esriJobNew"),
        SUBMITTED("esriJobSubmitted"),
        SUCCEEDED("esriJobSucceeded"),
        TIMED_OUT("esriJobTimedOut"),
        WAITING("esriJobWaiting");
        
        private String enumValue;

        public String value() {
            return this.enumValue;
        }

        JobStatus(String str) {
            this.enumValue = str;
        }

        public static JobStatus fromString(String str) {
            if ("esriJobCancelled".equals(str)) {
                return CANCELLED;
            }
            if ("esriJobCancelling".equals(str)) {
                return CANCELLING;
            }
            if ("esriJobDeleted".equals(str)) {
                return DELETED;
            }
            if ("esriJobDeleting".equals(str)) {
                return DELETING;
            }
            if ("esriJobExecuting".equals(str)) {
                return EXECUTING;
            }
            if ("esriJobFailed".equals(str)) {
                return FAILED;
            }
            if ("esriJobNew".equals(str)) {
                return NEW_JOB;
            }
            if ("esriJobSubmitted".equals(str)) {
                return SUBMITTED;
            }
            if ("esriJobSucceeded".equals(str)) {
                return SUCCEEDED;
            }
            if ("esriJobTimedOut".equals(str)) {
                return TIMED_OUT;
            }
            if ("esriJobWaiting".equals(str)) {
                return WAITING;
            }
            return null;
        }
    }

    public String getJobID() {
        return this.jobID;
    }

    public JobStatus getJobStatus() {
        return this.jobStatus;
    }

    public GPJobParameter[] getInputParameters() {
        return this.inputParameters;
    }

    public GPJobParameter[] getOutputParameters() {
        return this.outputParameters;
    }

    public GPMessage[] getMessages() {
        return this.messages;
    }

    public static GPJobResource fromJson(JsonParser jsonParser) throws Exception {
        if (!d.c(jsonParser)) {
            throw new EsriServiceException("Unable to parse the Response for this GPJobResource.");
        }
        GPJobResource gPJobResource = new GPJobResource();
        while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
            String currentName = jsonParser.getCurrentName();
            jsonParser.nextToken();
            if ("jobId".equals(currentName)) {
                gPJobResource.jobID = jsonParser.getText();
            } else if ("jobStatus".equals(currentName)) {
                gPJobResource.jobStatus = JobStatus.fromString(jsonParser.getText());
            } else if ("results".equals(currentName)) {
                if (jsonParser.getCurrentToken() == JsonToken.START_OBJECT) {
                    gPJobResource.outputParameters = GPJobParameter.fromJson(jsonParser);
                } else if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                    ArrayList arrayList = new ArrayList();
                    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                        if (jsonParser.getCurrentToken() == JsonToken.START_OBJECT) {
                            jsonParser.nextToken();
                            GPJobParameter gPJobParameter = new GPJobParameter();
                            gPJobParameter.setParamName(jsonParser.getCurrentName());
                            jsonParser.nextToken();
                            gPJobParameter.setParamURL(jsonParser.getText());
                            jsonParser.nextToken();
                            arrayList.add(gPJobParameter);
                        } else {
                            jsonParser.skipChildren();
                        }
                    }
                    gPJobResource.outputParameters = (GPJobParameter[]) arrayList.toArray(new GPJobParameter[0]);
                }
            } else if ("inputs".equals(currentName)) {
                if (jsonParser.getCurrentToken() == JsonToken.START_OBJECT) {
                    gPJobResource.inputParameters = GPJobParameter.fromJson(jsonParser);
                } else if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                        gPJobResource.inputParameters = GPJobParameter.fromJson(jsonParser);
                    }
                }
            } else if ("messages".equals(currentName)) {
                if (jsonParser.getCurrentToken() != JsonToken.START_ARRAY) {
                    jsonParser.skipChildren();
                } else {
                    ArrayList arrayList2 = new ArrayList();
                    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                        arrayList2.add(GPMessage.fromJson(jsonParser));
                    }
                    gPJobResource.messages = (GPMessage[]) arrayList2.toArray(new GPMessage[0]);
                }
            } else {
                jsonParser.skipChildren();
            }
        }
        return gPJobResource;
    }
}
